K
Khách

Hãy nhập câu hỏi của bạn vào đây, nếu là tài khoản VIP, bạn sẽ được ưu tiên trả lời.

#include <bits/stdc++.h>

using namespace std;

long long a[1000],i,n,j;

bool kt;

int main()

{

freopen("nguyento.inp","r",stdin);

freopen("nguyento.out","w",stdout);

cin>>n;

for (i=1; i<=n; i++) cin>>a[i];

for (i=1; i<=n; i++)

if (a[i]>1) 

{

kt=true;

for (j=2; j*j<=a[i]; j++)

if (a[i]%j==0) kt=false;

if (kt==true) cout<<a[i]<<" ";

}

return 0;

}

1:

const fi='Dulieu.txt';

fo='ketqua.txt';

var f1,f2:text;

a:array[1..100]of integer;

i,n:integer;

begin

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eof(f1) do 

  begin

inc(n);

read(f1,a[n]);

end;

for i:=1 to n do 

  if (a[i]>0) and (a[i] mod 2=0) then write(f2,a[i]:4);

close(f1);

close(f2);

end.

P/s: Cái này mình viết chương trình chính thôi nhé, còn hàm và thủ tục bạn tự viết nhé(chỉ cần lấy ý tưởng trong chương trình chính ra viết là được rồi)

2:

uses crt;

var a:array[1..100]of integer;

i,n,t:integer;

begin

clrscr;

write('Nhap n='); readln(n);

for i:=1 to n do

 begin

write('A[',i,']='); readln(a[i]);

end;

t:=0;

for i:=1 to n do 

  if a[i]>=0 then t:=t+a[i];

writeln(t);

readln;

end.

12 tháng 5 2021

program du_lieu;

uses crt;

var i,n:integer;

a:array[1..100]of integer;

tbc:real;

f:text;

begin

clrscr;

assign(f,'DULIEU.INP');reset(f);

readln(f,n);

for i:=1 to n do

begin

read(f,a[i]);

end;

close(f);

for i:=1 to n do

tbc:=tbc+a[i];

writeln(tbc/n);

readln;

end.

uses crt;

const fi='dulieu.txt';

var f1:text;

a,b:array[1..100]of integer;

n,i:integer;

begin

clrscr;

assign(f1,fi); reset(f1);

n:=0;

while not eof(f1) do 

begin

n:=n+1;

readln(a[n],b[n]);

end;

for i:=1 to n do 

  writeln(a[i]+b[i]);

close(f1);

readln;

end.

26 tháng 2 2022

Cho em cảm ơn ạ!

3 tháng 5 2021

Uses crt;

Var i,n,tong:integer;

      a:array[1..10000] of integer;

      f1,f2:text;

Begin

clrscr;

Assign(f1,'tinhtong.inp');

Assign(f2,'tinhtong.out');

tong:=0;

Reset(f1);readln(f1,n);

For i:= 1 to n do

Begin

read(f1,a[i]);

tong:=tong+a[i];

End;

close(f1);

rewrite(f2);

Writeln(f2,tong);

Readln;

End.

3 tháng 5 2021

Chị bổ sung dùm em thêm câu lệnh đóng file f2 nữa nha

 

uses crt;

const fi='dl.txt';

fo='soam.txt';

var f1,f2:text;

a:array[1..100]of integer;

i,n:integer;

begin

clrscr;

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eoln(f1) do 

  begin

n:=n+1;

read(f1,a[n]);

end;

for i:=1 to n do 

begin

  if a[i]>0 then writeln('Can bac hai cua ',a[i],' la: ',sqrt(a[i]):4:2)

else if a[i]<0 then write(f2,a[i]:4);

end;

close(f1);

close(f2);

readln;

end.

uses crt;

const fi='dl.txt';

fo='soam.txt';

var f1,f2:text;

a:array[1..100]of integer;

i,n:integer;

begin

clrscr;

assign(f1,fi); reset(f1);

assign(f2,fo); rewrite(f2);

n:=0;

while not eoln(f1) do 

  begin

n:=n+1;

read(f1,a[n]);

end;

for i:=1 to n do 

begin

  if a[i]>0 then writeln('Can bac hai cua ',a[i],' la: ',sqrt(a[i]):4:2)

else if a[i]<0 then write(f2,a[i]:4);

end;

close(f1);

close(f2);

readln;

end.